package com.qf.student.controller;


import com.qf.student.entity.Course;
import com.qf.student.response.R;
import com.qf.student.service.ICourseService;
import com.qf.student.utils.TokenUtils;
import com.qf.student.vo.input.AdminCourseInputVo;
import com.qf.student.vo.input.PageSearchInputVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-11-21
 */
@RestController
@RequestMapping("/course")
@Slf4j
public class CourseController {

    @Autowired
    private ICourseService courseService;

    @RequestMapping("/getCourseInfo")
    public R getCourseInfo(PageSearchInputVo inputVo, HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);
        inputVo.setId(userId);

        return courseService.getCourseInfo(inputVo);
    }

    @RequestMapping("/getCourseTable")
    public R getCourseTable(HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);

        return courseService.getCourseTable(userId);
    }

    @RequestMapping("/getTeacherCourse")
    public R getTeacherCourse(HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);

        return courseService.getTeacherCourse(userId);
    }

    /**
     * 查询老师的课程表
     *
     * @param request
     * @return
     */
    @RequestMapping("/getTeacherCourseTable")
    public R getTeacherCourseTable(HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);

        return courseService.getTeacherCourseTable(userId);
    }

    /**
     * 获得老是对应的学生的成绩信息
     * 以分页的形式返回查询到的数据
     *
     * @return
     */
    @RequestMapping("/getScoreInfo")
    public R getTeacherScoreInfo(PageSearchInputVo inputVo, HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);
        inputVo.setId(userId);

        return courseService.getTeacherScoreInfo(inputVo);
    }

    /**
     * 课程管理
     */
    @RequestMapping("/getAdminCourseInfo")
    public R getAdminCourseInfo(AdminCourseInputVo inputVo, HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);

        return courseService.getAdminCourseInfo(userId, inputVo);
    }

    @RequestMapping("/addCourseInfo")
    public R addCourseInfo(Course course, HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);
        return courseService.addCourseInfo(course, userId);
    }

    /**
     * 删除操作。删除课程
     * @param request
     * @return
     */
    @RequestMapping("/deleteCourse/{courseId}")
    public R deleteCourse(@PathVariable("courseId") Integer courseId, HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);
        return courseService.deleteCourse(courseId, userId);
    }


    @RequestMapping("/getCourseInfoById/{courseId}")
    public R getCourseInfoById(@PathVariable("courseId") Integer courseId, HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);
        return courseService.getCourseInfoById(courseId, userId);
    }


    @RequestMapping("/updateCourseInfo")
    public R updateCourseInfo(Course course, HttpServletRequest request) {
        Integer userId = TokenUtils.getUserId(request);
        return courseService.updateCourseInfo(course, userId);
    }


}
